package com.eig.courseweb.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.eig.common.entity.course.Teacher;
import com.eig.common.vo.Result;
import com.eig.courseweb.dao.ShouCangTeacherDao;
import com.eig.courseweb.service.ShouCangTeacherService;
import com.eig.courseweb.utils.IdWorker;
import com.eig.courseweb.vo.ShouCangVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ：StudentLsj（李世界）
 * @date ：Created in 2023/01/08 上午 08:40
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class ShouCangTeacherServiceImpl implements ShouCangTeacherService {

    @Resource
    private ShouCangTeacherDao shouCangTeacherDap;
    @Resource
    private IdWorker idWorker;

    @Override
    public Result findAttentionTeacherById(String huiYuanId) {
        List<Teacher> attentionTeacherById = shouCangTeacherDap.findAttentionTeacherById(huiYuanId);
        if (ObjectUtil.isNotEmpty(attentionTeacherById)) {
            return new Result(2000, "查询成功", attentionTeacherById
            );
        }
        return new Result(5000, "查询失败");
    }

    @Override
    public Result deleteFavoriteCourse(ShouCangVo s) {
        int i = shouCangTeacherDap.deleteFavoriteCourse(s);
        if (i > 0) {
            return new Result(2000, "取消成功", i);
        }
        return new Result(5000, "取消失败", i);
    }

    @Override
    public Result findAttentionTeacher(ShouCangVo s) {
        ShouCangVo attentionTeacher = shouCangTeacherDap.findAttentionTeacher(s);
        Map<String, Object> map = new HashMap<>();

        if (ObjectUtil.isNotEmpty(attentionTeacher)) {
            map.put("status", 1);
            return new Result(2000, "查询成功", map);
        }
        map.put("status", 0);
        return new Result(5000, "查询失败", map);
    }

    @Override
    public Result addAttentionTeacher(ShouCangVo s) {
        s.setCourseid(idWorker.nextId());
        shouCangTeacherDap.addAttentionTeacher(s);
        return new Result(2000,"操作成功");
    }
}
